package com.readpost.doman;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {

    //状态码
    private Integer code;

    //描述信息
    private String msg;

    //数据
    private T data;

    //返回成功的结果和数据
    public static <T> Result<T> success(T data) {
        return new Result<>(200, "success", data);
    }

    //返回成功的结果
    public static <T> Result<T> success() {
        return new Result<>(200,"success",null);
    }

    //返回失败的结果
    public static <T> Result<T> error(Integer code, String msg) {
        return new Result<>(code, msg,null);
    }

    //返回失败的结果
    public static <T> Result<T> fail(Integer code, String msg) {
        return new Result<>(code, msg, null);
    }

}
